
const { request } = require("../utils.js");

let http = {};

/**
 * @description: http请求方式埋点
 * @param {object} context 方法对象
 * @param {object} obj 埋点数据
 * @return {object} 结果
 */
http.request = async (context, obj) => {
  try{
    if (!context || !obj) {
      return {
        success: false,
        data: {},
        errorCode: "422",
        errorMessage: 'context or obj must be needed!'
      }
    }
    let url = '/tracking-mqtt-gateway/api/v1/rocket/tcp/producer?msg=' + encodeURIComponent(JSON.stringify(obj));

    return await request({
      method: "GET",
      hostname: "report.morefun.me",
      path: url
    });

  }catch(e){
    return {
      success: false,
      data: {},
      errorCode: "999",
      errorMessage: JSON.stringify(e)
    }
  }
}


module.exports = exports.http = http;